<template>

	<view>
		<u-navbar back-text="返回" title="每日记录" :is-back="isBack" :background="background"></u-navbar>

		<view class="u-m-t-20" v-for="item in list" :key="item.id" @click="showRecord(item.id)">
			<u-cell-group>
				<u-cell-item :title="getFormateDate(item.createTime)"> </u-cell-item>
			</u-cell-group>
		</view>
		<u-divider class="divider" v-if="isShow">没有更多数据了</u-divider>
	</view>

</template>



<script>
	export default {
		data() {
			return {
				isShow: false,
				background: {
					backgroundImage: 'linear-gradient(19deg, #21D4FD 0%, #B721FF 100%)'
				},
				isBack: true,
				list: [],
				time: null,
				page: {
					page: 1,
					size: 8
				}
			}
		},
		methods: {
			getFormateDate(time) {
				return time.substring(0, 10)
			},
			async getList() {
				const res = await this.$u.get('/record/getPage/' + this.page.page + '/' + this.page.size)
				console.info("每日记录列表数据", res.data.page.content)
				this.list = [...this.list, ...res.data.page.content]
				console.info("当前要显示的数据", this.list)
			},
			showRecord(id) {
				console.info("进入详细页")
				uni.navigateTo({
					url: '/pages/recordContent/recordContent?id=' + id
				})
			},
		},
		onLoad() {
			this.page.page = 1
			this.getList()
		},
		onShow() {
			// this.getList()
		},
		onUnload() {
			// this.list = []
		},
		onHide() {
			//this.list = []
		},
		onReachBottom() {
			if (this.list.length < this.page.page * 10) {
				this.isShow = true
				return
			}
			this.page.page++
			console.info("页面到底了")
			this.getList()
		},
		onPullDownRefresh() {
			console.info("开始下拉刷新")
			this.list = []
			this.page.page = 1
			setTimeout(() => {
				this.getList()
				uni.stopPullDownRefresh()
			}, 1000)
		}

	}
</script>

<style>
</style>
